<?php
header('Content-type: text/html; charset=utf-8');
#$url = "http://115.238.169.185/index.php?g=Api&m=GoodsApi&a=get_goods_inventory";
$url = "http://115.238.169.181/index.php?g=Api&m=GoodsApi&a=get_goods_inventory";
$time = time();
/*     字段名 是否必填    说明
system  是   类型，写：LM
DistributorId   是   String ,分销商Id
hgGoodsNo   否   海关号，根据不同海关号获取库存信息
pageRows    是   每页取几条，限取450条记录
pageSum 是   第几页
signStr 是   密钥，用于验证信息*/
$data['system']        = 'LM';
$data['DistributorId'] = "418";
$data['pageRows']      = "10";
$data['hgGoodsNo']      = "311718616060001517";
$data['pageSum']       = "1";
$signStr               = get_sign_str($data);
function get_sign_str($params)
{
    ksort($params);
    $paramStr = serialize($params) . 'fx.seabuy.com';
    echo "paramStr=".$paramStr;
    return md5($paramStr);
}
$data['signStr'] = $signStr;
var_dump(http_build_query($data));
$return_data     = getCurls($url, $data);
#$return_data     = json_decode($return_data, true);
echo "<pre>";
print_r($return_data);
echo "<pre>";


####产品信息
$url = "http://115.238.169.185/index.php?g=admin&m=ApiOrderNew&a=good_info";
$data2['AppSecret']='test123456';
$data2['Page'] = 1;
$data2['PageSize'] = 50;
$return_data2     = get_curl($url, $data2);
$return_data2     = json_decode($return_data2, true);
echo "<pre>";
print_r($return_data2);
echo "<pre>";



function get_curl($url, $post = false, $header = array())
{
    $ch      = curl_init();
    $timeout = 60;
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
    }
    if ($post && is_array($post)) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    } else {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    if ($header) {
        $headerArr = array();
        foreach ($header as $n => $v) {
            $headerArr[] = $n . ':' . $v;
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
    }

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $file_contents = curl_exec($ch);

    curl_close($ch);

    return $file_contents;
}
 function getCurls($url,$data=array()) {
        #write_log('java_api/'.date('Y-m')."/".date('d'), $data);
        
        $ch     =  curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        $datas = http_build_query($data);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $return =  curl_exec($ch);
        $return = json_decode($return, true);
        
        return $return;
    }
